import common from './common'
import paths from './paths'
import axios from 'axios'

const landService = {};

(function (service) {
    // 保存地块
    service.saveLandSource = function (data) {
      return common.post(paths.landSupply.saveLandSource, {}, data)
    }

    // 删除地块
    service.deleteLandSource = function (landId) {
        return common.get(paths.landSupply.deleteLandSource, { landId: landId })
    }

    // 更新地块
    service.updateLandState = function (landIds, state) {
      return common.get(paths.landSupply.updateLandState, { landIds: landIds, state: state })
    }

    // 业务关联地块图形
    service.businessDataCopy = function (params) {
      return common.post(window.config.VUE_APP_GIS + 'dmap-web/business/businessDataCopy', params, null)
    }

    // 业务取消关联地块图形
    service.deleteBusinessProject = function (data) {
      return common.post(window.config.VUE_APP_GIS + 'dmap-web/business/deleteBusinessProject', null, data)
    }

    // 业务的图形属性更新
    service.updateBusinessProject = function (data) {
      return common.post(window.config.VUE_APP_GIS + 'dmap-web/business/updateBusinessProject', null, data)
    }

    // 获取地块
    service.getLandSource = function (landId) {
      return common.get(paths.landSupply.getLandSource, { landId: landId })
    }

    // 更改拟供状态
    service.changeLandSupply = function (projectId, state) {
      return common.get(paths.landSupply.changeLandSupply, { projectId: projectId, state: state })
    }

    service.saveAllLandSource = function (data) {
      return common.post(paths.landSupply.saveAllLandSource, {}, data)
    }

    service.getMapJson = function () {
      return new Promise(resolve => {
        axios.get(paths.landSupply.getMapJson).then(resp => {
          resolve(resp.data)
        })
      })
    }

  // 取消项目树关联
  service.deleteRelation = function (projectId) {
    return common.get(paths.landSupply.deleteRelation, { projectId: projectId })
  }
})(landService)

export default landService
